import { useUserStore } from 'store/models/userStore'

// 请求拦截器
export const requestAuth = (config) => {
    const token = useUserStore().state.token
    if (token) {
        config.headers.Authorization = `Bearer ${token}`
    }

    //添加公共参数
    if (config.method === 'get') {
        config.params = {
            ...config.params,
            _t: Date.now() //防止缓存
        }
    }
    return config
}

// 请求错误处理
export const requestAuthErrorHandler = (error) => {
    return Promise.reject(error)
}